package com.lelv.framework.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport{

	private HttpServletRequest request;
	private HttpSession session;

	//返回请求的url
	public String getBackUrl(HttpServletRequest request){

		String url=request.getHeader("Referer");
		if(url==null || url.equals("")){
	      //如果请求的是ACTION 则通过该代码获取URL地址,当然可以完善其功能
	      url = request.getContextPath()+request.getServletPath()+"?"+request.getQueryString();
	    }
	    return url;
	}

	//空跳转
	public String doForward(){
		return SUCCESS;
	}

	public HttpServletRequest getRequest() {

		request = ServletActionContext.getRequest();

		return request;
	}

	public HttpSession getSession() {

		session = this.getRequest().getSession();

		return session;
	}

	public Long getCurrentUserId(){
		return (Long) getSession().getAttribute("adminId");
	}
}
